import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";

export default defineConfig({
  server: {
    cors: true,
    open: true,
    proxy: {
      "/api": {
        target: "https://www.zxycode.cloud",
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  build: {
    rollupOptions: {
      external: ["axios"],
    },
    commonjsOptions: {
      include: /node_modules/,
    },

  },
  plugins: [
    uni(),
    AutoImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/, // .vue
      ],
      imports: ["vue", "uni-app", "pinia"],
      dts: "typings/auto-imports.d.ts",
    }),
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
      "uview-plus": path.resolve(__dirname, "node_modules/uview-plus")
     
    },
    
  },
  // 优化依赖项
  optimizeDeps: {
    include: ["uview-plus"],
  },
  // 在Vite中配置scss并使用
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/styles/global.scss";',
      },
    },
  },
});
